package untiring07_HelloJDBC;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.BoxLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import java.awt.Font;

public class SungJUkNewData extends JDialog {
	private JTextField name;
	private JTextField kor;
	private JTextField eng;
	private JTextField mat;

	public SungJUkNewData(JFrame p) {
		setBounds(100, 100, 640, 480);
		setModal(true);
		setTitle("새성적");

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 100, 50, 50, 50, 50, 50, 50, 50,
				50, 50, 100, 0 };
		gbl_panel.rowHeights = new int[] { 100, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0,
				100, 0 };
		gbl_panel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		panel.setLayout(gbl_panel);

		JLabel titlelbl = new JLabel("성적을 입력하세요");
		titlelbl.setFont(new Font("굴림", Font.PLAIN, 14));
		GridBagConstraints gbc_titlelbl = new GridBagConstraints();
		gbc_titlelbl.gridwidth = 4;
		gbc_titlelbl.insets = new Insets(0, 0, 5, 5);
		gbc_titlelbl.gridx = 4;
		gbc_titlelbl.gridy = 1;
		panel.add(titlelbl, gbc_titlelbl);

		JLabel namelbl = new JLabel("이름");
		GridBagConstraints gbc_namelbl = new GridBagConstraints();
		gbc_namelbl.insets = new Insets(0, 0, 5, 5);
		gbc_namelbl.gridx = 2;
		gbc_namelbl.gridy = 2;
		panel.add(namelbl, gbc_namelbl);

		name = new JTextField();
		GridBagConstraints gbc_name = new GridBagConstraints();
		gbc_name.gridwidth = 3;
		gbc_name.insets = new Insets(0, 0, 5, 5);
		gbc_name.fill = GridBagConstraints.HORIZONTAL;
		gbc_name.gridx = 7;
		gbc_name.gridy = 2;
		panel.add(name, gbc_name);
		name.setColumns(10);

		JLabel korlbl = new JLabel("국어");
		GridBagConstraints gbc_korlbl = new GridBagConstraints();
		gbc_korlbl.insets = new Insets(0, 0, 5, 5);
		gbc_korlbl.gridx = 2;
		gbc_korlbl.gridy = 4;
		panel.add(korlbl, gbc_korlbl);

		kor = new JTextField();
		GridBagConstraints gbc_kor = new GridBagConstraints();
		gbc_kor.gridwidth = 3;
		gbc_kor.insets = new Insets(0, 0, 5, 5);
		gbc_kor.fill = GridBagConstraints.HORIZONTAL;
		gbc_kor.gridx = 7;
		gbc_kor.gridy = 4;
		panel.add(kor, gbc_kor);
		kor.setColumns(10);

		JLabel englbl = new JLabel("영어");
		GridBagConstraints gbc_englbl = new GridBagConstraints();
		gbc_englbl.insets = new Insets(0, 0, 5, 5);
		gbc_englbl.gridx = 2;
		gbc_englbl.gridy = 6;
		panel.add(englbl, gbc_englbl);

		eng = new JTextField();
		GridBagConstraints gbc_eng = new GridBagConstraints();
		gbc_eng.gridwidth = 3;
		gbc_eng.insets = new Insets(0, 0, 5, 5);
		gbc_eng.fill = GridBagConstraints.HORIZONTAL;
		gbc_eng.gridx = 7;
		gbc_eng.gridy = 6;
		panel.add(eng, gbc_eng);
		eng.setColumns(10);

		JLabel matlbl = new JLabel("수학");
		GridBagConstraints gbc_matlbl = new GridBagConstraints();
		gbc_matlbl.insets = new Insets(0, 0, 5, 5);
		gbc_matlbl.gridx = 2;
		gbc_matlbl.gridy = 8;
		panel.add(matlbl, gbc_matlbl);

		mat = new JTextField();
		GridBagConstraints gbc_mat = new GridBagConstraints();
		gbc_mat.gridwidth = 3;
		gbc_mat.insets = new Insets(0, 0, 5, 5);
		gbc_mat.fill = GridBagConstraints.HORIZONTAL;
		gbc_mat.gridx = 7;
		gbc_mat.gridy = 8;
		panel.add(mat, gbc_mat);
		mat.setColumns(10);

		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 입력한 성적데이터를 VO클래스에 저장
				EX01_SungJukService ss = new EX01_SungJukService();
				EX01_SungJukVO sj = new EX01_SungJukVO();
				EX01_SungJukDAO sd = new EX01_SungJukDAO();
				sj.setName(name.getText());
				sj.setKor(Integer.parseInt(kor.getText()));
				sj.setEng(Integer.parseInt(eng.getText()));
				sj.setMat(Integer.parseInt(mat.getText()));
				// VO에 저장된 데이터를
				// Service 클래스의 insertSungJuk()에 전달
				if (sd.insertSungJuk(sj))
					JOptionPane.showMessageDialog(null, "입력성공");
				else
					JOptionPane.showMessageDialog(null, "입력실패");
			}
		});
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton.gridx = 8;
		gbc_btnNewButton.gridy = 11;
		panel.add(btnNewButton, gbc_btnNewButton);

		JButton btnNewButton_1 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
		gbc_btnNewButton_1.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton_1.gridx = 9;
		gbc_btnNewButton_1.gridy = 11;
		panel.add(btnNewButton_1, gbc_btnNewButton_1);
		setVisible(true);

	}
}